package com.jmm.api.controller.sms;

import com.jmm.api.service.sms.ApiSmsValidateService;
import com.jmm.common.annotation.Log;
import com.jmm.common.utils.Result;
import com.jmm.common.utils.ShiroUtils;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/smscode/")
public class SmsCodeController {
    @Autowired
    private ApiSmsValidateService apiSmsValidateService;

    @GetMapping("getRegisterCode")
    @Log("api 获取验证码")
    @ApiOperation("api 获取注册验证码")
    public Result<?> getRegisterCode(@RequestParam("phone")Long phone) {
        apiSmsValidateService.getRegisterCode(phone);
        return Result.ok();
    }
    @GetMapping("getForgetCode")
    @Log("api 获取验证码")
    @ApiOperation("api 获取忘记密码验证码")
    public Result<?> getForgetCode(@RequestParam("phone")Long phone) {
        apiSmsValidateService.getForgetCode(phone);
        return Result.ok();
    }
    @GetMapping("getLoginCode")
    @Log("api 获取验证码")
    @ApiOperation("api 获取登录验证码")
    public Result<?> getLoginCode(@RequestParam("phone")Long phone) {
        apiSmsValidateService.getLoginCode(phone);
        return Result.ok();
    }
    @GetMapping("getChangePhoneCode")
    @Log("api 获取验证码")
    @ApiOperation("api 获取更换手机号验证码")
    @RequiresAuthentication
    @ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "Authorization", paramType = "header") })
    public Result<?> getChangePhoneCode() {
        apiSmsValidateService.getChangePhoneCode(ShiroUtils.getUserId());
        return Result.ok();
    }
    @GetMapping("getBandingPhoneCode")
    @Log("api 获取验证码")
    @ApiOperation("api 获取绑定新手机验证码")
    @RequiresAuthentication
    @ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "Authorization", paramType = "header") })
    public Result<?> getBandingPhoneCode(@RequestParam("phone")Long phone) {
        apiSmsValidateService.getBandingPhoneCode(phone);
        return Result.ok();
    }

}
